package main

import (
	"fmt"
	"sort"
)

func groupAnagrams(strs []string) [][]string {
	res := make([][]string, 0)
	mapString := make(map[string][]string, 0)
	for _, str := range strs {
		s := []byte(str)
		//排序
		sort.Slice(s, func(i, j int) bool { return s[i] < s[j] })
		fmt.Println(string(s))
		mapString[string(s)] = append(mapString[string(s)], str)
	}
	fmt.Println(mapString)
	for _, v := range mapString {
		res = append(res, v)
	}
	fmt.Println(res)
	return res
}

func main() {
	strs := []string{"eat", "tea", "tan", "ate", "nat", "bat"}
	groupAnagrams(strs)
}
